<%--                                                                       --%>
<%-- Copyright (c) 2001-2004 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<script language="javascript">

<%--
(1)  actionName, REQUIRED. You can use one of the 10 new actions listed in webtools\root\modules\common\WEB-INF\conf\struts-config-mt.xml. 
		They are:	/mt/categoryPickerPopup
					/mt/categoryPickerPopupMultiSelect
					/mt/categorySearchPickerPopup
					/mt/categorySearchPickerPopupMultiSelect
					/mt/pickerPopup
					/mt/pickerPopupMultiSelect
					/mt/pickerPopupSearch
					/mt/pickerPopupSearchMultiSelect
					/mt/pickerPopupUncategorized
					/mt/pickerPopupUncategorizedMultiSelect
					
(2)  callback, REQUIRED. This is the name of the call back function. It can be any name as long as it match the actual javascript function name in your jsp file.  The function has to have two parameters. They are used to pass back the selected items info. The first one is an array of the selected content item ids, and the other is an array of the selected content item names.
(3)  cntId, REQUIRED. Content type id. 
(4)  currentCatId. This is to set the current category id. Set it to null to use default root category.
(5)  existingItemIds. A list of previously selected content ids. This list of selected content ids will be passed in as a string. Each content id is separated by a delimiter ';'  Here is how this string should look like, 123;456;789. This string contains 3 content ids, 123, 456, and 789. If there is no previously selected content id, a null or an empty string can be used.
(6)  columnName. The name of the column from which to retrieve values to display in the content items list. If this parameter is null or an empty string, the content key will be used to display in the content items list.
(7)  browseTab. Pass in true or null to display the browse tab; false to hide it. 
(8)  searchTab. Pass in true or null to display the search tab; false to hide it.
(9)  uncateTab. Pass in true or null to display the uncategorized tab; false to hide it.
	 	Note:	Tab will not be hidden if the action requires that tab. 
				For example, the search tab will still be displayed when using "/mt/pickerPopupSearch" as the action name and pass in false to parameter searchTab.
(10) cntFilterClass. A fully qualified name of a class to perform filtering on content items. Specify null for no filtering.
(11) catFilterClass. A fully qualified name of a class to perform filtering on categories. Specify null for no filtering.
(12) minSelection. This is to set the minimum number of items need to be picked. If no minimum selection is required, set it to 0. Set this to null in order to use the default minimum value, 1. 
(13) rootSelection. This is only for /mt/categoryPickerPopup, single selection of category. Set this value to true or null to display "Root" category for selection. Set it to false to hide it.
(14) filterClassData. This is a string type parameter. This is used to pass data into the cntFilterClass and catFilterClass via the filter interface method. Set it to null or an empty string if no data to pass in.
(15) defaultSearchResultIds. This is used to pass in a list of default search result ids. The list of ids will be passed in as a string. Each id is separated by a delimiter ';' Here is how this string should look like, 123;456;789. This string contains 3 ids, 123, 456, and 789. If there is no need to display default search result, a null or an empty string can be used.
(16) showAllCategories. This is used to indicate showing the 'Include all categories' checkbox or not. Set to true or null to show it; false to hide instead.
(17) allCategories. This is used to indicate initial value of the 'Include all categories' checkbox. Set to false or null to not include all categories; true to include all categories.
 --%>
  
  function doPickerPopupAction(actionName, callback, cntId, currentCatId, existingItemIds, 
    columnName, browseTab, searchTab, uncateTab, cntFilterClass, catFilterClass, minSelection, 
    rootSelection, filterClassData, defaultSearchResultIds, showAllCategories, allCategories) {
  	var DELIM = '%24%23@!';
    var popupUrl = actionName;
    if (popupUrl != null) {
      if (popupUrl.indexOf("?") < 0) {
        popupUrl += "?";
      } 
      else {
        popupUrl += "&";
      }
    }

    popupUrl += 'callback=' + callback;
    popupUrl += '&contentTypeId=' + cntId;
    popupUrl += '&parentFormName=' + 'abc';
    
    if (currentCatId != null) {
    	if (currentCatId.length != 0) {
    		// Check if it is an negative integer
    		if (checkPattern(currentCatId.toString(), "(0)|[-]\\d+")) {
    			popupUrl += '&currentCategoryOid=' + currentCatId;
    		}// if
    	}// if
    }// if
    
    if (existingItemIds != null) {
	    if (existingItemIds.length != 0) {
	    	var ids = new Array();
	    	ids = existingItemIds.split(';');
	    	popupUrl += '&existingItemIds=';
	    	var i = 0;
	    	for (i = 0; i < ids.length; i++) {
	    		if (ids[i].length != 0) {
		    		if (i > 0) {
		    			popupUrl += DELIM;
		    		}// if
		    		popupUrl += ids[i];
		    	}// if
	    	}// for
	    }// if
	}// if

	if (columnName != null) {
	    if (columnName.length != 0) {
			popupUrl += '&columnName=' + columnName;
	    }// if
	}// if
	
	if (browseTab != null && !browseTab) {
		popupUrl += '&browseTab=' + false;
	}// if
	
	if (searchTab != null && !searchTab) {
		popupUrl += '&searchTab=' + false;
	}// if
	
	if (uncateTab != null && !uncateTab) {
		popupUrl += '&uncateTab=' + false;
	}// if
	
	if (cntFilterClass != null && cntFilterClass.length != 0) {
		popupUrl += '&cntFilterClass=' + cntFilterClass;
	}// if
	
	if (catFilterClass != null && catFilterClass.length != 0) {
		popupUrl += '&catFilterClass=' + catFilterClass;
	}// if
	
	if (minSelection != null && minSelection.length != 0) {
		// check if it's a position integer
		if (checkPattern(minSelection.toString(), "\\d+")) {
			popupUrl += '&minSelection=' + minSelection;
		}// if
	}// if
	
	if (rootSelection != null && !rootSelection) {
		popupUrl += '&rootSelection=' + false;
	}// if
	
	if (filterClassData != null && filterClassData.length != 0) {
		popupUrl += '&filterClassData=' + filterClassData;
	}// if
	
	if (defaultSearchResultIds != null) {
	    if (defaultSearchResultIds.length != 0) {
	    	var ids = new Array();
	    	ids = defaultSearchResultIds.split(';');
	    	popupUrl += '&defaultSearchResultIds=';
	    	var i = 0;
	    	for (i = 0; i < ids.length; i++) {
	    		if (ids[i].length != 0) {
		    		if (i > 0) {
		    			popupUrl += DELIM;
		    		}// if
		    		popupUrl += ids[i];
		    	}// if
	    	}// for
	    }// if
	}// if
	
	if (showAllCategories != null && !showAllCategories) {
		popupUrl += '&showAllCategories=' + false;
	}// if

	if (allCategories != null && allCategories) {
		popupUrl += '&allCategories=' + true;
	}// if
	
    var windowFeatures = 'width=600,height=600,scrollbars=yes,resizable=yes';
    var popupWindow = window.open(popupUrl, 'abc', windowFeatures);
    if (popupWindow != null) {
      if (popupWindow.opener == null) {
        popupWindow.opener = self;
      }
    }
    popupWindow.focus();
    return popupWindow;
  }

  function checkPattern(s, p){
	var regExp = new RegExp(p, "g");
	var result = s.match(regExp);
	if (result != null){
		for(i = 0; i < result.length; i++){
	      if (result[i] == s){
	        return true;
	      }
	    }
	}
  	return false;
  }
</script>
